<template>
  <div class="type-nav">
    <div class="container">
      <h2 class="all">全部商品分类</h2>
      <nav class="nav">
        <a href="###">服装城</a>
        <a href="###">美妆馆</a>
        <a href="###">尚品汇超市</a>
        <a href="###">全球购</a>
        <a href="###">闪购</a>
        <a href="###">团购</a>
        <a href="###">有趣</a>
        <a href="###">秒杀</a>
      </nav>
      <div class="sort">
        <div class="all-sort-list2">
          <div class="item bo" v-for="(cl1,index) in categoryList" :key="cl1.categoryId">
            <h3 @mouseenter="changeCurrentIndex(index)" @mouseleave="changeCurrentIndex(-1)" :class="{mouseFocus:index==currentIndex}">
              <a href="">{{ cl1.categoryName }}</a>
            </h3>
            <div class="item-list clearfix">
              <div class="subitem">
                <dl class="fore" v-for="(cl2,index) in cl1.categoryChild" :key="cl2.categoryId">
                  <dt>
                    <a href="">{{ cl2.categoryName }}</a>
                  </dt>
                  <dd>
                    <em v-for="(cl3,index) in cl2.categoryChild" :key="cl3.categoryId">
                      <a href="">{{ cl3.categoryName }}</a>
                    </em>
                  </dd>
                </dl>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: "typeNav",
  data() {
    return {
      currentIndex: -1
    }
  },
  computed: {
    ...mapState({
      categoryList: (state) => state.home.categoryList,
    })
  },
  methods: {
    changeCurrentIndex(index) {
      this.currentIndex = index;
    }
  },
}
</script>

<style scoped lang="less">
.type-nav {

  border-bottom: 2px solid red;
  background: white;

  .container {
    width: @base-width;
    margin: 0 auto;
    display: flex;
    position: relative;

    .all {
      width: 210px;
      height: 45px;
      line-height: 45px;
      color: white;
      background-color: red;
      text-align: center;
      font-size: 14px;
      font-weight: 700;
    }

    .nav {
      a {
        margin: 0 22px;
        height: 45px;
        line-height: 45px;
        font-size: 16px;
        color: #333;
      }
    }

    .sort {
      position: absolute;
      left: 0;
      top: 45px;
      width: 210px;
      height: 500px;
      background: #fafafa;
      z-index: 999;

      .all-sort-list2 {
        .item {
          h3 {
            padding: 0 20px;
            overflow: hidden;
            line-height: 34px;
            font-size: 14px;
            font-weight: 400;

            a {
              color: #333;
            }

            &.mouseFocus {
              background: skyblue;
            }

          }


          .item-list {
            display: none;
            position: absolute;
            top: 0;
            left: 210px;
            width: 650px;
            min-height: 500px;
            background: #f7f7f7;
            border: 1px solid #ddd;

            .subitem {
              float: left;
              padding: 0 2px 0 8px;
              width: 650px;

              .fore {
                border-top: 1px solid #eee;
                padding: 6px 0;
                overflow: hidden;
                zoom: 1;

                dt {
                  float: left;
                  width: 60px;
                  line-height: 22px;
                  padding: 0 3px;
                  font-weight: 700;
                  text-align: right;

                }

                dd {
                  float: left;
                  width: 490px;
                  line-height: 24px;

                  em {
                    padding: 0 3px;
                    border-left: 1px solid #ccc;
                  }
                }
              }

            }


          }

          &:hover {
            .item-list {
              display: block;
            }

          }
        }
      }
    }

  }
}
</style>
